#ifndef RUP_H
#define RUP_H

#include "common.h"
#include "stm32f10x.h"

/* -------------------------------------- Datatype Defines -------------------------------------- */
typedef struct                                                 
{
	uint8_t           header[2];
	uint8_t           length[2];
	uint8_t           encytype[1];
	uint8_t           ssn[6];
	uint8_t           dsn[6];
	uint8_t           content_and_checksum[1300];
}RUPDATA;

typedef struct
{
	uint32_t	state;
	uint32_t	pt;
	RUPDATA		rxframe;
	uint16_t	total_length;
	uint16_t	content_length;
	uint16_t	checksum;
	uint8_t		sequence[2];
	uint8_t		type;
	//uint8_t		key[16];
}RUPSS;


typedef struct                                                 
{
	uint32_t   len;
	uint8_t    data[1300];
}RUPFRAME;

typedef struct                                                 
{
	uint8_t Randnum[16];
	uint8_t decryptbuf[16];
}GENERATEKEY;
//Generate_Key


RUPDATA Rup_createFrame(uint8_t* ssn, uint8_t* dsn, uint8_t encytype, uint8_t random, uint8_t* sequence, uint8_t type, uint8_t* payload, uint16_t payload_length,uint8_t* aeskey);
extern uint32_t Rup_parseFrame(RUPSS* parse_state, void (*handler_fun)(RUPSS*), uint8_t rxdata, uint8_t* sm4key);
extern RUPFRAME Rup_createNotification(uint16_t pid, uint16_t stype, uint8_t* data, uint32_t data_len);
extern RUPFRAME Rup_createRequestRead(uint16_t pid, uint16_t stype, uint8_t* data, uint32_t data_len);
extern RUPFRAME Rup_createRequestWrite(uint8_t aid, uint16_t sid, uint16_t pid, uint8_t* data, uint32_t data_len);
//extern RUPFRAME Rup_createResponse(uint8_t aid, uint16_t sid, uint8_t fncode, uint16_t pid, uint8_t result, uint8_t* data, uint32_t data_len);
extern RUPFRAME Rup_createResponse(uint16_t pid, uint16_t stype, uint8_t* data, uint32_t data_len);
#endif